<template>
  <div>
    <span style="line-height: 100px; font-weight: bolder; margin: 0 20px">
      缴费编号：{{ data.list.contractId }}
    </span>
  </div>
  <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
    <el-tab-pane label="基本信息" name="first">
      <el-table
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        :data="data.list"
        stripe
        style="width: 100%"
      >
        <el-table-column prop="houseId" label="房屋编号" min-width="25%" />
        <el-table-column prop="contractId" label="合同编号" min-width="25%" />
        <el-table-column prop="user.realName" label="签约方" min-width="25%" />
        <el-table-column
          prop="startTime"
          label="合同开始时间"
          min-width="25%"
        />
      </el-table>
      <el-table
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        :data="data.list"
        stripe
        style="width: 100%"
      >
        <el-table-column prop="endTime" label="合同完结时间" min-width="25%" />
        <el-table-column label="缴费月账期" min-width="25%">
          <template #default="scope">
            <div>
              {{
                (year - parseInt(scope.row.startTime.substr(0, 4))) * 12 +
                  month -
                  parseInt(scope.row.startTime.substr(6, 2))
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="是否欠费" min-width="25%">
          <div>{{ isPay }}</div>
        </el-table-column>
        <el-table-column label="更新时间" min-width="25%">
          <div>{{ year + '-' + month + '-' + day }}</div>
        </el-table-column>
      </el-table>
    </el-tab-pane>
    <el-tab-pane label="缴费项" name="second">
      <el-table :data="payList" style="width: 100%; margin-bottom: 20px" border>
        <el-table-column prop="propertyItem.name" label="缴费项" />
        <el-table-column prop="dosage" label="用量" />
        <el-table-column prop="propertyItem.price" label="单价" />
        <el-table-column label="应缴费金额">
          <template #default="scope">
            <div v-if="scope.row.dosage != null">
              {{ scope.row.dosage * scope.row.propertyItem.price }}
            </div>
            <div v-else-if="scope.row.propertyItem.unit == '月'">
              {{ scope.row.propertyItem.price }}
            </div>
            <div v-else>0</div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentRecord.createDate" label="缴费日期" />
        <el-table-column prop="month" label="缴费账期" />
        <el-table-column label="是否缴费">
          <template #default="scope">
            <div
              v-if="scope.row.paymentRecord.paymentType == null"
              style="color: red;"
            >
              否
            </div>
            <div v-else style="color: green;">是</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="personname" label="备注" /> -->
      </el-table>
    </el-tab-pane>
    <el-tab-pane label="缴费记录" name="third">
      <el-table
        :data="payList.filter(item => item.paymentRecord.paymentType != null)"
        style="width: 100%; margin-bottom: 20px"
        border
      >
        <!-- <el-table-column>
        <div>{{ payList.filter(item=>item.paymentRecord.paymentType!=null) }}</div>
      </el-table-column> -->
        <el-table-column prop="month" label="账单期" />
        <el-table-column label="缴费金额">
          <template #default="scope">
            <div v-if="scope.row.dosage != null">
              {{ scope.row.dosage * scope.row.propertyItem.price }}
            </div>
            <div v-else-if="scope.row.propertyItem.unit == '月'">
              {{ scope.row.propertyItem.price }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="paymentRecord.createDate" label="缴费时间" />
        <el-table-column label="缴费状态">缴费成功</el-table-column>
        <el-table-column prop="personname" label="付款账号" />
        <el-table-column prop="personname" label="付款人" />
        <el-table-column label="付款方式">
          <template #default="scope">
            <div v-if="scope.row.paymentRecord.paymentType == 1">微信</div>
            <div v-else-if="scope.row.paymentRecord.paymentType == 2">
              支付宝
            </div>
            <div v-else-if="scope.row.paymentRecord.paymentType == 3">
              银行卡
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-tab-pane>
  </el-tabs>
</template>
<script setup>
import { selectConPayList, selectPayMess } from '@/api/charge'
import { onMounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'

const data = reactive({
  list: [],
})
var payItem = ref([])
var year = ref(0)
var month = ref(0)
var day = ref(0)
var isPay = ref('否')
var payList = ref([])
onMounted(async () => {
  var now = new Date()
  year.value = now.getFullYear()
  month.value = now.getMonth() + 1
  day.value = now.getDate()
  // payItem.value = (await propertyItemList()).data
})
setTimeout(async () => {
  payList.value = (await selectPayMess(data.list[0].houseId)).data
  payList.value.forEach(item => {
    if (item.paymentRecord.paymentType == null) {
      isPay.value = '是'
      return
    }
  })
}, 2000)
var router = useRoute()
data.list.push(JSON.parse(router.query.rowData))
</script>
